package mju.cxf.controller.employee;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import mju.cxf.constant.MessageConstant;
import mju.cxf.dto.OrderDTO;
import mju.cxf.dto.ProductDTO;
import mju.cxf.entity.Order;
import mju.cxf.handler.OrderCode;
import mju.cxf.result.Result;
import mju.cxf.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;

@RestController
@Api(tags = "订单接口列表")
@RequestMapping("/employee/api/order")
public class EOrderController {


    @Autowired
    private OrderService orderService;

    /**
     * 创建订单信息
     */
    @PostMapping("/create")
    public Result createOrder(@RequestBody ProductDTO productDTO){

        /*先新建一个订单*/
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        LocalDateTime creationtiem = LocalDateTime.now();    //创建时间
//        String oid = OrderCode.getOrderCode();               //订单编号
////        Double amount = (double) productDTO.getCount();      //总金额
//        Integer productId = productDTO.getId();
//
//        System.out.println(order);
//        return  orderService.insertOrder(order) ?
//            Result.success(MessageConstant.SUCCESS_MESSAGE):
//            Result.error(MessageConstant.FAILURE_MESSAGE);
return null;

    }

    /**
     * 删除管理员信息
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除商品信息", notes = "管理员通过此接口删除商品信息")
    public Result<String> deleteProduct(@PathVariable Integer id) {
        return orderService.deleteProduct(id) ?
                Result.success(MessageConstant.SUCCESS_MESSAGE) :
                Result.error(MessageConstant.FAILURE_MESSAGE);
    }
    /**
     * 分页查询订单信息
     * @return 分页查询结果
     */
    @GetMapping("/pages")
    public Page<OrderDTO> getUsersByUsername(@RequestParam(value = "number",required = false) String number,
                                             @RequestParam(value = "userId",required = false) Integer userId,
                                             @RequestParam(value = "productName",required = false) String productName,
                                             @RequestParam(value = "status",required = false) Integer status,
                                             @RequestParam(value = "current",defaultValue = "1") int current,
                                             @RequestParam(value = "size",defaultValue = "10") int size) {
        return orderService.selectPageBynumber(number, userId, productName, status, current, size);
    }
}
